/*
 * GDO GeometryFactory
 * 
 * initial implementation : 31.8.2007
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
using System;
using System.Collections.Generic;
using System.Text;
using Petra.Gis.Geometry;
using Petra.Gis.Geometry.Support;

namespace Petra.Gis.DataServices.GDO
{
  public unsafe partial class GeometryFactory
  {
    /***********************************************
    * 28.8.2007
    * 
    * creates Arc
    * from intergraph blob structure
    * 
    * asida@centrum.cz, initial implementation
    *************************************************/
    private static GeometryBase binaryToArc(byte[] vData, int arrayOffset, System.Type parentGeomType)
    {
      Arc oGeom = new Arc();

      oGeom.coordList = new CoordinateList(vData, 16, 2, Dimension.dim3D);
      oGeom.normalVector = new NormalVector(ref vData, 64);
      //oGeom.radius = new scalarValue(ref vData, 88).value;

      fixed (byte* beginCoord = &vData[88])
      {
        oGeom.radius = *((double*)beginCoord);
      }

      return oGeom;
    }






    /***********************************************
    * 28.8.2007
    * 
    * creates intergraph blob structure 
    * from Arc
    * 
    * asida@centrum.cz, initial implementation
    *************************************************/
    private static byte[] arcToBinary(GeometryBase geometry)
    {
      int lBlobSize;
      Guid gGeomGUID;

      Arc _arc = (Arc)geometry;

      lBlobSize = 16 + (80);
      gGeomGUID = getGuid[GeometryType.Arc];

      System.IO.MemoryStream oIMStream = new System.IO.MemoryStream(lBlobSize);
      System.IO.BinaryWriter mBWriter = new System.IO.BinaryWriter(oIMStream);

      oIMStream.Position = 0;
      mBWriter.Write(gGeomGUID.ToByteArray());

      mBWriter.Write(_arc.coordList.ToArray(Dimension.dim3D));

      //todo:fuck !! do something w/ this shit !!!
      mBWriter.Write((double)_arc.normalVector.I);
      mBWriter.Write((double)_arc.normalVector.J);
      mBWriter.Write((double)_arc.normalVector.K);

      mBWriter.Write(_arc.radius);

      return oIMStream.ToArray();
    }


  }
}
